package net.jwtools.tmt.service;

import java.util.List;

import net.jwtools.tmt.dao.hibernate.PersonHibernateDAO;
import net.jwtools.tmt.domain.Person;
import net.jwtools.tmt.domain.Status;

/**
 * @author Naftali van der Loon
 * 
 * This service to Persons
 */

public class PersonService implements TMTService {
	private PersonHibernateDAO dao;

	public void setDao(PersonHibernateDAO personDAO) {
		this.dao = personDAO;
	}

	public PersonHibernateDAO getDao() {
		return dao;
	}

	public List<Person> getAllPersons() {
		List<Person> persons = null;
		persons = dao.findAll();
		return persons;
	}

	public List<Person> getAllActivePersons() {
		List<Person> persons = null;
		persons = dao.findAllActive();
		return persons;
	}
	public Person getPersonById(Long id) {
		Person person = null;
		person = dao.findById(id);
		return person;
	}

	public void removePerson(Person person) {
		// TODO check if person has outstanding territories

		person.setStatus(Status.INACTIVE);
		dao.saveOrUpdate(person);
	}
}
